﻿using Assets.Script.Human.Enemy.Actions;
using Assets.Script.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.SocialPlatforms;

namespace Assets.Script.Human.Enemy.Enemys
{
    class MeleeEnemyAI:EnemyAI
    {
        private static GameObject loseBoold;
        public static GameObject dropCoin;
        public static GameObject dropMilk;
        public static GameObject dieEffect;
        /*
        public override void Init()
        {
   
            if (loseBoold == null)
            {
                loseBoold = Resources.Load<GameObject>(ResourcePath.LoseBoold);
            }
            if (dropCoin==null)
            {
                dropCoin= Resources.Load<GameObject>(ResourcePath.DropItem.Coin);
            }
            if (dropMilk == null)
            {
                dropMilk = Resources.Load<GameObject>(ResourcePath.DropItem.Milk);
            }
            if (dieEffect==null)
            {
                dieEffect = Resources.Load<GameObject>(ResourcePath.EnemyDeathEffect);
            }

            switch (level)
            {
                case 1:
                    body.Data.MaxHp = new BaseData(10);
                    body.Data.Damage = new BaseData(3);
                    break;
                case 2:
                    body.Data.MaxHp = new BaseData(20);
                    body.Data.Damage = new BaseData(6);
                    break;
                case 3:
                    body.Data.MaxHp = new BaseData(30);
                    body.Data.Damage = new BaseData(10);
                    break;
                case 4:
                    body.Data.MaxHp = new BaseData(40);
                    body.Data.Damage = new BaseData(12);
                    break;
                case 5:
                    body.Data.MaxHp = new BaseData(50);
                    body.Data.Damage = new BaseData(15);
                    break;
                default:
                    break;
            }

            body.ReInit();

            
            actions.Init(
                new IAction[]
                {
                                new Idle(body),
                                new Follow(body),
                                new RangeAtk(body),
                                new MeleeAtk(body),
                                new BeAtk(body),
                                new Idle(body),
                                new Die(body),
                }
                );
            
        }

        */

        protected override void HurtReaction_Effect(Vector3 positonDir, ref float force, ref float forceTime)
        {
            var clo = Instantiate(loseBoold, transform.position, new Quaternion(), null);
            Destroy(clo, 1f);
        }

        protected override void Drop()
        {
            var r = UnityEngine.Random.Range(0, 100);
            if (r<=30)
            {
                if (UnityEngine.Random.Range(0,2)<1)
                {
                    Instantiate(dropCoin, transform.position, new Quaternion(), null);
                }
                else
                {
                    Instantiate(dropMilk, transform.position, new Quaternion(), null);
                }
                
            }
        }
        public override void Die()
        {
            var  de = Instantiate(dieEffect, transform.position, new Quaternion(), null);
            Destroy(de,2f);
        }
    }
}